{extend name="common/common" /}

{block name="style"}
<style type="text/css">
.container-fluid .btn.btn-sm{
    float: right;
    margin-left: 10px;
}
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>附件列表</h5>
        </div>
        <div class="ibox-content">
            <div class="container-fluid">
				{if authCheck('attachment/uploadattach')}
                <button class="btn btn-info btn-sm" data-multiple="true" data-action='' data-upload="">上传附件</button>
				{/if}
				{if authCheck('attachment/setattachstatus')}
                <button class="btn btn-primary btn-sm getIDs" data-ext="" data-setstatus="setAttachStatus" data-param="">
                    翻转状态
                </button>
				{/if}
				{if authCheck('attachment/delattach')}
                <button class="btn btn-danger btn-sm getIDs" data-delete="delAttach" data-param="">删除附件</button>
				{/if}
            </div>
            <table id="cusTable">
                <thead>
                    <th>checkbox</th>
                    <th data-field="id">ID</th>
                    <th data-field="name">附件名称</th>
                    <th data-field="url">附件链接</th>
                    <th class="text-center" data-field="ext">附件类型</th>
                    <th class="text-center" data-field="size">附件大小(Mb)</th>
                    <th class="text-center" data-field="download">下载次数</th>
                    <th class="text-center" data-field="create_time">上传时间</th>
					{if authCheck('attachment/setattachstatus')}
                    <th class="text-center" data-field="statusText">状态</th>
					{/if}
                </thead>
            </table>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
var IDs = '';
function initTable() {
    //先销毁表格
    $('#cusTable').bootstrapTable('destroy');
    //初始化表格,动态从服务器加载数据
    $("#cusTable").bootstrapTable({
        method: "get",  //使用get请求到服务器获取数据
        url: "./index", //获取数据的地址
        striped: true,  //表格显示条纹
        pagination: true, //启动分页
        pageSize: 10,  //每页显示的记录数
        pageNumber:1, //当前第几页
        pageList: [5, 10, 15, 20, 25],  //记录数可选列表
        sidePagination: "server", //表示服务端请求
        paginationFirstText: "首页",
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        paginationLastText: "尾页",
        queryParamsType : "undefined",
        columns : [{
            checkbox: true,
            formatter:function(value,row,index){
                if (row.state == true){
                    return {
                        checked : value,//设置选中
                    };
                }
                return value;
            },
        }],
        queryParams: function queryParams(params) {   //设置查询参数
            var param = {
                pageNumber: params.pageNumber,
                pageSize: params.pageSize,
            };
            return param;
        },
        onLoadSuccess: function(res){  //加载成功时执行
            if(111 == res.code){
                window.location.reload();
            }
            layer.msg("加载成功", {time : 1000});
        },
        onLoadError: function(){  //加载失败时执行
            layer.msg("加载数据失败");
        }
    });
}

$(function(){
    //调用函数，初始化表格
    initTable();
    //当点击查询按钮的时候执行
    $("#search").bind("click", initTable);

    $('.getIDs').on('click',function(){
        var checkedOn= $('#cusTable').bootstrapTable('getSelections');
        var IDs = '';
        for(var i=0;i<checkedOn.length;i++){
            if(i == 0){
                IDs = checkedOn[0].id;
            }else{
                IDs += ',' + checkedOn[i].id;
            }

        }
        $('.getIDs').attr('data-param',IDs);
    })
});
</script>
{/block}
